from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from time import sleep


import sys

sys.path.append(r'..')
from web_base.base_page import BasePage
from page_object.login_page import LoginPage

class AssetPage(BasePage):
    url = r'/bsams/front/asset/asset_list.do'

    #新增定位
    add_ben_loc=(By.XPATH,'//*[@id="leftmenu_asset_manage"]/div[1]/a/img')
    add_btn_loc=(By.CLASS_NAME,'button_true')
    add_title_loc = (By.ID, 'title')
    add_providerId_loc = (By.ID, 'providerId')
    add_storageId_loc = (By.ID, 'storageId')
    add_ok_loc = (By.CLASS_NAME, 'button_fujian.margin')

    def asset_add(self,name,providerId,storageId):
        self.open()
        self.ele_click(self.add_ben_loc)
        sleep(2)
        self.ele_click(self.add_btn_loc)
        self.input_ele(self.add_title_loc,name)
        self.ele_select(self.add_providerId_loc,providerId)
        self.ele_select(self.add_storageId_loc,storageId)
        self.ele_click(self.add_ok_loc)
        sleep(3)
        text=self.get_alert_text()
        self.alert_click()
        return text

if __name__ == '__main__':
    name = '赵家军事委员会'
    providerId = '维信科技发展有限公司'
    storageId = '电脑设备库'

    chrome_location = r'D:\测试工具\Win_x64_1135105_chrome-win\chrome-win\chrome.exe'
    options = webdriver.ChromeOptions()
    options.binary_location = chrome_location
    driver_location = r'D:\测试工具\pythan\chromedriver.exe'
    service = Service(driver_location)

    driver=webdriver.Chrome(options=options,service=service)

    login_page = LoginPage(driver)
    login_page.login()

    asset_page = AssetPage(driver)
    asset_page.asset_add(name, providerId, storageId)


    driver.quit()
